package com.trembear.carclient.api;

import com.alibaba.fastjson.JSON;
import com.ucar.base.common.Result;
import com.ucar.base.common.resultUtil.RemoteCommConstant;
import com.ucarinc.base.ucarincadmin.login.yccadmin.V1.YccAdminLoginDTO;
import com.ucarinc.base.ucarincadmin.login.yccadmin.V1.YccAdminLoginRe;
import org.springframework.stereotype.Service;

/**
 * Description: 优车统一登录.
 * All Rights Reserved.
 * @version 1.0 2017-10-16 16:35:59 by 刘庆魁（qk.liu@zuche.com）创建
 */
@Service
public class UcarincadminClientService extends BaseClientService{

	/**
	 * Description: yccadmin远程到incadmin登录校验.
	 * All Rights Reserved.
	 * @version 1.0 2018年1月13日9:50:39 by 宋孝东（xd.song@zuche.com）创建
	 */
	@SuppressWarnings("unchecked")
	public YccAdminLoginRe yccAdminLogin(String username, String password){
		YccAdminLoginDTO dto = new YccAdminLoginDTO();

		dto.setUsername(username);
		dto.setPassword(password);

		String serviceName = "ucarincadmin.login.yccadmin.V1.yccAdminLogin";

		//为了避免password参数在异常时被模板方法输出, 独立处理异常
		Result<YccAdminLoginRe> result = null;
		try {
			result = (Result<YccAdminLoginRe>) executeToObject(serviceName, dto);
		} catch (Exception e){
			logger.error("[CALL-EX]{}:username:{}", serviceName, username, e);
			return null;
		}

		if( result==null ){
			logger.error("[CALL-NULL]{}:username:{}", serviceName, username);
			return null;
		}

		if( result.getStatus()!= RemoteCommConstant.REMOTE_SUCCES_STATUS ){
			logger.error("[CALL-STATUS]{}:username:{},{}", serviceName, username, JSON.toJSONString(result));
			return null;
		}

		YccAdminLoginRe re = (YccAdminLoginRe) result.getRe();
		return re;
	}

}
